import { postLogin } from '@/api/login'
import { setUserToken,clearUserToken } from '@/utils/handleCookie'

const state={
    Token:'',//vuex 存一份/cookice再存一份
};
const getters={
    
};
const mutations={
    CHANGE_TOKEN(state,playload){
        state.Token=playload
    }
    

};
const actions={
    //异步登录
    Acs_loginApi(context,playload){
        return new Promise((resolve,reject)=>{
            postLogin(playload)
            .then(res=>{
                //console.log(context);
                let {token}=res;
                context.commit('CHANGE_TOKEN',token);
                setUserToken(token);
                resolve(res)
            })
            .catch(err=>{
                reject(err)
            })
        })
    },
    //异步清除userToken
    Acs_clearUserToken(context,playload){
        return new Promise(resolve=>{
            resolve()
        })
    }
};
export default {
    namespaced:true,
    state,
    getters,
    mutations,
    actions
}
